package com.wanmait.happyheating.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.happyheating.pojo.MaterialsType;
import com.wanmait.happyheating.mapper.MaterialsTypeMapper;
import com.wanmait.happyheating.service.MaterialsTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 耗材分类表 服务实现类
 * </p>
 *
 * @author yuQianTao
 * @since 2021-05-13
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MaterialsTypeServiceImpl extends ServiceImpl<MaterialsTypeMapper, MaterialsType> implements MaterialsTypeService {

    @Resource
    private MaterialsTypeMapper materialsTypeMapper;

    @Override
    public PageInfo<MaterialsType> findMaterialsTypeByPage(Integer pageNum,Integer pageSize) {
        //pagesize
        PageHelper.startPage(pageNum,pageSize);
        List<MaterialsType> materialsTypes = materialsTypeMapper.selectList(null);
        //navigatePages
        PageInfo<MaterialsType> materialsTypePageInfo = new PageInfo<>(materialsTypes,5);

        return materialsTypePageInfo;
    }

    @Override
    public PageInfo<MaterialsType> likeMaterialsTypeByPage(Integer pageNum,Integer pageSize, String title) {
        LambdaQueryWrapper<MaterialsType> materialsTypeLambdaQueryWrapper = new LambdaQueryWrapper<>();
        materialsTypeLambdaQueryWrapper.like(MaterialsType::getTitle,title);

        PageHelper.startPage(pageNum,pageSize);
        List<MaterialsType> materialsTypes = materialsTypeMapper.selectList(materialsTypeLambdaQueryWrapper);
        PageInfo<MaterialsType> materialsTypePageInfo = new PageInfo<>(materialsTypes,5);

        return materialsTypePageInfo;
    }
}
